package stringExertises;

import java.util.Scanner;

/**
 * @author: bamboo_shoot
 * @date: 20/2/4 0:20
 * @description: 例如，键盘录入 abc，输出结果 cba
 */
public class Reversal {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入abc");
        String s = sc.nextLine();
        char[] chars = s.toCharArray();
//        traverse(chars);
        reversal(chars,s);
        traverse(chars);
    }

    private static void reversal(char[] chars,String s) {
        char temp;
        for (int start = 0, end = s.length() - 1; start < end; start++, end--) {
            temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
        }
    }

    private static void traverse(char[] chars) {
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i]+" ");
        }
    }
}
